# Initialize App Engine and import the default settings (DB backend, etc.).
# If you want to use a different backend you have to remove all occurences
# of "djangoappengine" from this file.
from djangoappengine.settings_base import *

import os
import sys
PROJDIR = os.path.abspath(os.path.dirname(__file__))
sys.path.extend([os.path.join(PROJDIR, 'libs')])

HTTP_HOST = os.environ.get('HTTP_HOST')

DEBUG = True

SECRET_KEY = '21oiu312sadasdasda4h1297asawerq34dasd214g23oub'

INSTALLED_APPS = (
    'django.contrib.contenttypes',
    'django.contrib.humanize',
    'django.contrib.sessions',
    'django.contrib.admin',
    'django.contrib.auth',
    'djangotoolbox',
    'transurlvania',
    'modeltranslation',
    'pillarsapp',
    'google_api_oauth',
    'sushi_and_tears_redux',
    
    # djangoappengine should come last, so it can override a few manage.py commands
    'djangoappengine',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.locale.LocaleMiddleware',
    'transurlvania.middleware.URLTransMiddleware',
    'transurlvania.middleware.LangInPathMiddleware',
    'transurlvania.middleware.URLCacheResetMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'pillarsapp.middleware.RequestObjectMiddleware',
    'django.middleware.common.CommonMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
    'django.core.context_processors.i18n',
    'django.contrib.auth.context_processors.auth',
    'transurlvania.context_processors.translate',
    'sushi_and_tears_redux.context_processors.translator',
)

TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'))
SEARCH_BACKEND = 'search.backends.gae_background_tasks'

# This test runner captures stdout and associates tracebacks with their
# corresponding output. Helps a lot with print-debugging.
TEST_RUNNER = 'djangotoolbox.test.CapturingTestSuiteRunner'

ADMIN_MEDIA_PREFIX = '/media/admin/'

ROOT_URLCONF = 'urls'

# I18N
gettext = lambda s: s
USE_L10N = True
LANGUAGES = (
    ('en', gettext('English')),
    ('ar', gettext('Arabic')),
)
LANGUAGE_CODE = 'en'
TRANSURLVANIA_DEFAULT_LANG = LANGUAGE_CODE
MODELTRANSLATION_TRANSLATION_REGISTRY = 'pillarsapp.translation'
MODELTRANSLATION_DEFAULT_LANGUAGE = LANGUAGE_CODE

# A Google Spreadsheet will have a URL
# e.g. https://docs.google.com/a/google.com/spreadsheet/ccc?key=0Ai6imo2MxGTXdG82RUdmOVl3RkFBaW5jV19UY3pqcmc#gid=0
#Use the 'key=' value from the Spreadsheet URL for this setting
TRANSLATION_SPREADSHEET_KEY = "0Ajsea70QP5zcdE4zcVZZUlFEdzZndk5DMGNTQVhjb0E"

# Alternatively, use the Spreadsheet title
#TRANSLATION_SPREADSHEET_TITLE = "Pillars test translations"

# Specify the sheet name. If none is specified, "Sheet1" will be presumed
TRANSLATION_SPREADSHEET_SHEET_NAME = "Sheet1"

# Cache times
HTTP_CACHE_TIME = 60 * 15 
MC_CACHE_TIME = 60 * 15 
#HTTP_CACHE_TIME = 0 

# HOSTNAME used in oauth
HOSTNAME = 'http://%s' % HTTP_HOST
# OAuth settings
OAUTH_SETTINGS = {
    # See https://code.google.com/apis/console. These are specific to pillarsofsupport
    'client_id':'199596406233-iejshua8ss7qjos9g0v5pdbutf42pk92.apps.googleusercontent.com',
    'client_secret':'-meRz0Jw6qQKm9gDW3qcI6r1',
    # The URL on your site Google will send people to once they approve/deny access
    'redirect_uri':'%s/oauth2callback' % HOSTNAME,
    'scope':'https://spreadsheets.google.com/feeds/',
    'scopes':'https://spreadsheets.google.com/feeds/',
    # See http://code.google.com/apis/accounts/docs/OAuth2.html. You probably won't need to change these.
    'login_url':'https://accounts.google.com/o/oauth2/auth',
    'token_url':'https://accounts.google.com/o/oauth2/token',
    'user_agent': 'appengine/pillarsofsupport'
}

OAUTH_DEFAULT_REDIRECT = 'page_view'
OAUTH_FAILED_REDIRECT = 'auth-failed'
OAUTH_SESSION_KEYS = ['user','credentials','flow']

# Activate django-dbindexer if available
try:
    import dbindexer
    DATABASES['native'] = DATABASES['default']
    DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': 'native'}
    INSTALLED_APPS += ('dbindexer',)
    DBINDEXER_SITECONF = 'dbindexes'
    MIDDLEWARE_CLASSES = ('dbindexer.middleware.DBIndexerMiddleware',) + \
                         MIDDLEWARE_CLASSES
except ImportError:
    pass
